from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-21 14:02:10.984863
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 21, Feb, 2022
Time: 14:02:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2129
Nobs: 574.000 HQIC: -48.6292
Log likelihood: 6792.73 FPE: 5.82138e-22
AIC: -48.8954 Det(Omega_mle): 4.98331e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.347543 0.068381 5.082 0.000
L1.Burgenland 0.106519 0.041568 2.563 0.010
L1.Kärnten -0.110893 0.021643 -5.124 0.000
L1.Niederösterreich 0.188788 0.086632 2.179 0.029
L1.Oberösterreich 0.133073 0.085717 1.552 0.121
L1.Salzburg 0.254707 0.043991 5.790 0.000
L1.Steiermark 0.036260 0.058069 0.624 0.532
L1.Tirol 0.100286 0.046853 2.140 0.032
L1.Vorarlberg -0.069652 0.041304 -1.686 0.092
L1.Wien 0.020284 0.076191 0.266 0.790
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052726 0.147576 0.357 0.721
L1.Burgenland -0.038111 0.089709 -0.425 0.671
L1.Kärnten 0.041450 0.046708 0.887 0.375
L1.Niederösterreich -0.204925 0.186963 -1.096 0.273
L1.Oberösterreich 0.461440 0.184989 2.494 0.013
L1.Salzburg 0.282078 0.094938 2.971 0.003
L1.Steiermark 0.113545 0.125322 0.906 0.365
L1.Tirol 0.304475 0.101114 3.011 0.003
L1.Vorarlberg 0.025541 0.089141 0.287 0.774
L1.Wien -0.028808 0.164430 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199756 0.034926 5.719 0.000
L1.Burgenland 0.089016 0.021231 4.193 0.000
L1.Kärnten -0.007408 0.011054 -0.670 0.503
L1.Niederösterreich 0.239329 0.044247 5.409 0.000
L1.Oberösterreich 0.161974 0.043780 3.700 0.000
L1.Salzburg 0.039665 0.022468 1.765 0.077
L1.Steiermark 0.026576 0.029659 0.896 0.370
L1.Tirol 0.081919 0.023930 3.423 0.001
L1.Vorarlberg 0.053680 0.021096 2.545 0.011
L1.Wien 0.117572 0.038915 3.021 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120922 0.034865 3.468 0.001
L1.Burgenland 0.043525 0.021194 2.054 0.040
L1.Kärnten -0.013085 0.011035 -1.186 0.236
L1.Niederösterreich 0.168548 0.044170 3.816 0.000
L1.Oberösterreich 0.337537 0.043704 7.723 0.000
L1.Salzburg 0.100536 0.022429 4.482 0.000
L1.Steiermark 0.110682 0.029608 3.738 0.000
L1.Tirol 0.090366 0.023889 3.783 0.000
L1.Vorarlberg 0.060956 0.021060 2.894 0.004
L1.Wien -0.020235 0.038847 -0.521 0.602
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121821 0.065717 1.854 0.064
L1.Burgenland -0.046496 0.039948 -1.164 0.244
L1.Kärnten -0.045259 0.020799 -2.176 0.030
L1.Niederösterreich 0.135295 0.083256 1.625 0.104
L1.Oberösterreich 0.165797 0.082377 2.013 0.044
L1.Salzburg 0.283940 0.042276 6.716 0.000
L1.Steiermark 0.057964 0.055806 1.039 0.299
L1.Tirol 0.155889 0.045027 3.462 0.001
L1.Vorarlberg 0.097261 0.039695 2.450 0.014
L1.Wien 0.076639 0.073222 1.047 0.295
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080767 0.051221 1.577 0.115
L1.Burgenland 0.025831 0.031136 0.830 0.407
L1.Kärnten 0.053474 0.016212 3.299 0.001
L1.Niederösterreich 0.188632 0.064891 2.907 0.004
L1.Oberösterreich 0.330234 0.064206 5.143 0.000
L1.Salzburg 0.034491 0.032951 1.047 0.295
L1.Steiermark 0.005825 0.043497 0.134 0.893
L1.Tirol 0.120236 0.035095 3.426 0.001
L1.Vorarlberg 0.066276 0.030939 2.142 0.032
L1.Wien 0.096040 0.057071 1.683 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170413 0.061902 2.753 0.006
L1.Burgenland 0.004372 0.037629 0.116 0.907
L1.Kärnten -0.065932 0.019592 -3.365 0.001
L1.Niederösterreich -0.107371 0.078423 -1.369 0.171
L1.Oberösterreich 0.208353 0.077595 2.685 0.007
L1.Salzburg 0.053980 0.039823 1.356 0.175
L1.Steiermark 0.248765 0.052567 4.732 0.000
L1.Tirol 0.499705 0.042413 11.782 0.000
L1.Vorarlberg 0.064438 0.037391 1.723 0.085
L1.Wien -0.073494 0.068972 -1.066 0.287
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160142 0.068675 2.332 0.020
L1.Burgenland -0.003224 0.041746 -0.077 0.938
L1.Kärnten 0.062815 0.021736 2.890 0.004
L1.Niederösterreich 0.165178 0.087004 1.899 0.058
L1.Oberösterreich -0.053467 0.086085 -0.621 0.535
L1.Salzburg 0.207349 0.044180 4.693 0.000
L1.Steiermark 0.139376 0.058319 2.390 0.017
L1.Tirol 0.055769 0.047054 1.185 0.236
L1.Vorarlberg 0.147146 0.041482 3.547 0.000
L1.Wien 0.121954 0.076518 1.594 0.111
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393802 0.040267 9.780 0.000
L1.Burgenland -0.003060 0.024477 -0.125 0.901
L1.Kärnten -0.021367 0.012744 -1.677 0.094
L1.Niederösterreich 0.200416 0.051013 3.929 0.000
L1.Oberösterreich 0.229821 0.050475 4.553 0.000
L1.Salzburg 0.037111 0.025904 1.433 0.152
L1.Steiermark -0.017065 0.034194 -0.499 0.618
L1.Tirol 0.090962 0.027589 3.297 0.001
L1.Vorarlberg 0.050969 0.024322 2.096 0.036
L1.Wien 0.041450 0.044865 0.924 0.356
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036260 0.101645 0.169235 0.136205 0.095491 0.081486 0.032216 0.210112
Kärnten 0.036260 1.000000 -0.027805 0.132396 0.048294 0.085489 0.443946 -0.067219 0.089188
Niederösterreich 0.101645 -0.027805 1.000000 0.309518 0.119021 0.269238 0.065665 0.151227 0.287326
Oberösterreich 0.169235 0.132396 0.309518 1.000000 0.214402 0.293556 0.167424 0.136071 0.234019
Salzburg 0.136205 0.048294 0.119021 0.214402 1.000000 0.123823 0.091149 0.104362 0.124286
Steiermark 0.095491 0.085489 0.269238 0.293556 0.123823 1.000000 0.134058 0.106138 0.031885
Tirol 0.081486 0.443946 0.065665 0.167424 0.091149 0.134058 1.000000 0.062237 0.151690
Vorarlberg 0.032216 -0.067219 0.151227 0.136071 0.104362 0.106138 0.062237 1.000000 -0.005170
Wien 0.210112 0.089188 0.287326 0.234019 0.124286 0.031885 0.151690 -0.005170 1.000000